<?php
namespace app\index\controller;
use think\Db;
use think\Session;
use think\Controller;

class Index extends Base
{
    public function index()
    {
		//获取用户id
		$admin_uid = Session::get("admin_uid");
        //查出用户组rules
		$admin_info = db("auth_group g")->join("f_auth_group_access ga","g.id = ga.group_id")
			->where("ga.uid",$admin_uid)->field("g.rules")->find();
		$where ['id'] = array("in",$admin_info['rules']);
		$where ['pid'] = 0;
        $res=db('auth_rule')->where($where)->select();
		foreach($res as $k=>$v){
			$res[$k]['son']=db('auth_rule')->where('pid',$v['id'])->select();
		}


		//dump($res);
		
		return view('index',['res'=>$res]);

    }
    public function welcome()
    {
        //时间
        $timestart=date("Y-m-d 00:00:00");
        $timeend=date("Y-m-d H:i:s");
        //实名
        $reals=db('real')
            ->where('rflg',1)
            ->count();
        //随你压
        $suiyas=db('suiya')->count();
        $this->assign('suiyas',$suiyas);
        //帮你踩
        $bangcais=db('bangcai')->count();
        $this->assign('bangcais',$bangcais);
        //委托采购
        $weituos=db('caigou')->count();
        $this->assign('weituos',$weituos);
        //今日实名
        $real=db('real')
            ->where('f_real.s_createtime','between',[$timestart,$timeend])
            ->count();
        $this->assign('reals',$reals);
        //今日转发
        $zhuanfa=db('zhuanfa')
            ->where('f_zhuanfa.z_createtime','between',[$timestart,$timeend])
            ->count();
        //今日拨号
        $bohao=db('bohao')
            ->where('f_bohao.b_createtime','between',[$timestart,$timeend])
            ->count();
        $this->assign('bohao',$bohao);
        //今日注册
        $yonghu=db('user')
            ->where('f_user.createtime','between',[$timestart,$timeend])
            ->count();
        $this->assign('yonghu',$yonghu);
        //今日评论
        $pinglun=db('comments')
            ->where('f_comments.ccreatetime','between',[$timestart,$timeend])
            ->count();
        //今日收费
        $pay=db('pay')
            ->field('f_pay.price,f_pay.creaetime')
            ->where('flg','已支付')
            ->where('f_pay.createtime','between',[$timestart,$timeend])
            ->sum('f_pay.price');
        $zpay=db('zpay')
            ->where('flg','已支付')
            ->field('f_zpay.price,f_zpay.creaetime')
            ->where('f_zpay.createtime','between',[$timestart,$timeend])
            ->sum('f_zpay.price');
        $pays=$pay+$zpay;
        $this->assign('pays',$pays);
        //今日信息流
        $xinxi=db('message')
            ->where('f_message.createtime','between',[$timestart,$timeend])
            ->count();
        //今日感兴趣
        $praise=db('praise')
            ->where('f_praise.createtime','between',[$timestart,$timeend])
            ->count();
        $this->assign('praise',$praise);
        //注册用户
        $yonghus=db('user')->where('phone','neq','')->count();
        $this->assign('yonghus',$yonghus);
        //累计收费
        $pay=db('pay')
            ->where('flg','已支付')
            ->field('f_pay.price')
            ->sum('f_pay.price');
        $zpay=db('zpay')
            ->where('flg','已支付')
            ->field('f_zpay.price')
            ->sum('f_zpay.price');
        $payss=$pay+$zpay;
        $this->assign('payss',$payss);
        //信息流
        $xinxis=db('message')->count();
        $this->assign('xinxis',$xinxis);
        return view('welcome',['zhuanfa'=>$zhuanfa,'pinglun'=>$pinglun,'xinxi'=>$xinxi,'real'=>$real]);
    }

	
    //退出登录代码
    public function tuichu()
    {
        Session(null);
        $this->redirect('index/index/login');
    }
}
